package tree.nodeType.Boolean.functions;

import java.util.ArrayList;
import java.util.Random;

import pools.PoolsManager;
import tree.Node;
import tree.TreeNodesManager;
import tree.nodeType.BooleanFunction;
/**
 *Not operator, has 1 boolean son 
 *
 */
public class NotOperator extends BooleanFunction{

	public NotOperator(Node parent, int depth, int maxDepth, TreeNodesManager treeNodesManager) {
		super(1, parent,depth);	
		if (treeNodesManager!=null){
			treeNodesManager.addNode(this);
		}		
		initSons(depth,maxDepth,treeNodesManager);
	}
	
	@Override
	protected ArrayList<Node> getProperNodesManagerList(
			TreeNodesManager treeNodeManager) {		
		return null;
	}
	
	public NotOperator() {}
	
	@Override
	public void initSons(int depth, int maximumDepth, TreeNodesManager treeNodesManager) {
		sons.add(PoolsManager.get().getRandomBooleanNode(depth+1, maximumDepth, this, treeNodesManager));
	}

	@Override
	public boolean execute() {
		return (!((BooleanFunction)sons.get(0)).execute());
	}

	@Override
	public String toString() {
		
		return "Not(!) operator";
	}

	@Override
	public Node getRandNodeWithTheSameReturnType(int maxDepth,TreeNodesManager tnm){
		return PoolsManager.get().getRandomBooleanNode(getDepth(),maxDepth, getParent(),tnm);
	}
	@Override
	public Node getRandNode(int maxDepth,TreeNodesManager tnm){
		return null;
	}

	@Override
	protected Node clone(TreeNodesManager treeNodesManager,Node parent) {
		Node cloned= new NotOperator(this,treeNodesManager,parent);		
		return cloned;
	}
	
	@Override
	protected Node clone(Node parent) {
		Node cloned= new NotOperator(this,parent);		
		return cloned;
	}
	
	public NotOperator(NotOperator notOp,Node parent){
		this.depth=notOp.depth;
		this.parent=parent;
		this.sonsNeeded=notOp.sonsNeeded;
		this.random= new Random();
		this.sons= new ArrayList<Node>();
		for (Node son : notOp.sons){
			this.sons.add(son.cloneSubTree(this));
		}
	}
	public NotOperator(NotOperator notOp, TreeNodesManager treeNodesManager,Node parent){
		super(1,parent,notOp.depth);
		if (treeNodesManager!=null){
			treeNodesManager.addNode(this);
		}
		for (Node son : notOp.sons){
			this.sons.add(son.cloneSubTree(treeNodesManager,this));
		}
	}


	
}
